package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.LocalUser;
import com.xinhe.web.response.LoginView;
import com.xinhe.web.service.LocalUserService;
import com.xinhe.web.vo.LocalUserModel;
import com.xinhe.web.vo.LocalUserUpdateModel;
import com.xinhe.web.vo.LocalUserUpdatePasswordModel;
import com.xinhe.web.vo.LocalUserView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = "本地用户", tags = {"本地用户"})
@RestController
@RequestMapping(value = {"/localUser"}, produces = {"application/json;charset=UTF-8"})
public class LocalUserController {
    @Autowired
    private LocalUserService localUserService;

    @ApiOperation(httpMethod = "POST", value = "平台登录")
    @PostMapping({"/login"})
    public Result<LocalUserView> login(@RequestParam(name = "username") String username, @RequestParam(name = "password") String password) {
        return localUserService.login(username,password);
    }
    @ApiOperation(httpMethod = "POST", value = "平台登录")
    @PostMapping({"/login1"})
    public Result<LoginView> login1(@RequestParam(name = "username") String username, @RequestParam(name = "password") String password) {
        return localUserService.login1(username,password);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询本地用户")
    @RequestMapping({"/pageLocalUser"})
    public QueryResults<LocalUserView> pageLocalUser(String username, int pageNum, int pageSize) {
        return this.localUserService.pageLocalUser(username,pageNum,pageSize);
    }

    @ApiOperation(httpMethod = "POST", value = "商家登录")
    @PostMapping({"/sellerLogin"})
    public Result sellerLogin(@RequestParam(name = "username") String username, @RequestParam(name = "password") String password) {
        return Result.ok();
    }

    @ApiOperation(httpMethod = "GET", value = "用户信息")
    @GetMapping({"/userInfo"})
    public Result userInfo() {
        return Result.ok();
    }

    @ApiOperation(httpMethod = "DELETE", value = "退出登录")
    @DeleteMapping({"/logout"})
    public Result logout() {
        //删除redis中token信息，再加个拦截器
        return Result.ok();
    }

    @ApiOperation(httpMethod = "POST", value = "修改系统用户")
    @RequestMapping({"/updateLocalUser"})
    public Result updateUser(@RequestBody @Valid LocalUserUpdateModel model, BindingResult bind) {
        return Result.ok();
    }

    @ApiOperation(httpMethod = "POST", value = "修改系统用户密码")
    @RequestMapping({"/updateUserPwd"})
    public Result updateUserPwd(@Valid LocalUserUpdatePasswordModel model, BindingResult bind) {
        return Result.ok();
    }

    @ApiOperation(httpMethod = "POST", value = "保存本地用户")
    @RequestMapping({"/saveLocalUser"})
    public Result saveLocalUser(@RequestBody @Valid LocalUserModel model) {
        return localUserService.saveLocalUser(model);
    }


    @ApiOperation(httpMethod = "GET", value = "删除本地用户")
    @ApiImplicitParam(name = "localUserId", value = "标识", required = true)
    @RequestMapping({"/deleteLocalUser"})
    public Result deleteLocalUser(Long localUserId) {
        return Result.ok();
    }

    @ApiOperation(httpMethod = "GET", value = "本地用户详情")
    @ApiImplicitParam(name = "localUserId", value = "标识", required = true)
    @RequestMapping({"/detailLocalUser"})
    public Result detailLocalUser(Long localUserId) {
        return Result.ok();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("findUserInfoByPage")
    public QueryResults<LocalUser> findUserInfoByPage(Integer pageNum, Integer pageSize){
        return localUserService.findUserInfoByPage(pageNum, pageSize);
    }



}

